#include<bits/stdc++.h>
using namespace std;

class person
{
public:
	int _price;
	int _count;
	person(int price = 0, int sum = 0) :
		_price(price), _count(sum)
	{}
};

int main()
{
	int n, m;
	cin >> n >> m;
	vector<person>arr(m);
	for (int i = 0; i < m; i++)
	{
		cin >> arr[i]._price >> arr[i]._count;
	}
	/*priority_queue<person>(arr.begin(), arr.end(), [](const person& p1, const person& p2) {
		return p1._price < p2._price;
		});*/
	sort(arr.begin(),arr.end(), [](const person& p1, const person& p2) { 
		return p1._price < p2._price;  
		}); 
	int sum = 0; 
	for (int i = 0; i < m; i++)
	{
		if (n >= arr[i]._count)//全部买下
		{
			sum += arr[i]._count * arr[i]._price;
			n -= arr[i]._count;//更新剩下所需要的个数
		}
		else//需要的少于奶农的牛奶总数
		{
			sum += n * arr[i]._price;
			n -= n;         
			break;
		}
	}
	cout << sum << endl; 
	return 0;
}